<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<div class="form-group">	
								<label class="col-sm-2 control-label">评分年度：</label>
								<div class="col-sm-4">
									<input id="deptId" name="year"th:value="${year}" class="form-control readonly" type="text" >
								</div>
								<label class="col-sm-2 control-label">评分月度：</label>
								<div class="col-sm-4">
									<input id="deptId" name="month" readonly th:value="${month}" class="form-control readonly" type="text">
								</div>
							</div>
							<div class="form-group row-sel" th:each="dept :${deptList}">
								<input class="hidden" th:name="'list['+${deptStat.index}+'].teamName'" th:value="${dept.name}"/>	
								<input class="hidden" th:name="'list['+${deptStat.index}+'].deptId'" th:value="${dept.deptId}"/>	
								<label class="col-sm-2 control-label" th:text="${dept.name}"></label>
								<div class="col-sm-4">
									<!-- <input  th:name="'list['+${deptStat.index}+'].ord'" class="form-control ord" type="text" placeholder="排名"> -->
									<select th:name="'list['+${deptStat.index}+'].ord'" required class="form-control ord">
										<option value="">--选择排名--</option>
									</select>
								</div>
								<div class="col-sm-6">
									<input  th:name="'list['+${deptStat.index}+'].score'" readonly="readonly" class="form-control score" type="text" placeholder="评分">
								</div>
								<!-- <div class="col-sm-4">
									<input name="deptId" class="form-control" type="text">
								</div> -->
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/per/team/add.js">
	</script>
	<script type="text/javascript">
		$(function(){
			$('.ord').mouseover(function(){
				var ord = $(this).val();
				getArray()
				if(ord == '' || ord == 'undefined' || ord == null){
				}else{
					array[ord]=parseInt(ord);
				}
				$(this).html(createOrd(array,ord));
			})
			
			$('.ord').change(function(){
				var ord = $(this).val();
				$score = $(this).closest('.form-group').find('.score');
				if(ord == '' || ord == 'undefined' || ord == null){
					$score.val("");
				}else{
					$score.val(getScore(ord)); 
				}
			})
		})
		
		//数组初始化
		var array = init();
		function init(){
			var size = $('.row-sel').length;
			console.log("size:",size)
			var str = new Array();
			for(var i=0;i<=size;i++){
				str.push(i);
			}
			return str;
		}
		//创建排名下拉列表
		function createOrd(array,ord){
			var obj = '';
			for(var i=0;i<array.length;i++){
				if(i==0){
					obj += '<option value="">--选择排名--</option>';
				}else if(array[i] != 0  ){
					if( array[i]== ord){
						obj += '<option value="'+i+'" selected>'+i+'</option>';
					}else{
						obj += '<option value="'+i+'">'+i+'</option>';
					}
				}
			}
			return obj;
		}
		//数组重新赋值
		function getArray(){
			
			$('.ord').each(function(){
				init();
				var ord = $(this).val()
				if(ord == '' || ord == 'undefined' || ord == null){
					
				}else{
					array[ord]=0;
				}
			})
			
		}
		
		function save() {
			$.ajax({
				cache : true,
				type : "POST",
				url : "/per/team/saveScoreByTeam",
				data : $('#signupForm').serialize(),// 你的formid
				async : false,
				error : function(request) {
					parent.layer.alert("Connection error");
				},
				success : function(data) {
					if (data.code == 0) {
						location="/tips/success";

					} else {
						location="/tips/fail";
					}

				}
			});

		}
	</script>
</body>
</html>
